package com.zhao.integration.test;

import javax.jms.Message;
import javax.jms.TextMessage;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;

import com.zhao.integration.config.JmsConfig;
import com.zhao.integration.jms.MessageReceiver;
import com.zhao.integration.jms.MessageSender;
import com.zhao.test.UnitTesting;

public class JmsRunnerTesting extends UnitTesting {
	@Autowired
	MessageReceiver messageReceiver;

	@Autowired
	MessageSender messageSender;

	@Autowired
	JmsTemplate jmsTemplate;

	@Test
	public void contextLoads() {

	}

	/**
	 * 利用jmsTemplate接受消息
	 * 
	 * @throws Exception
	 */
	@Test
	public void testReceiveMessage() throws Exception {
		while (true) {
			Message message = jmsTemplate.receive();
			if (message instanceof TextMessage) {
				TextMessage textMessage = (TextMessage) message;
				System.out.println(textMessage.getText());
			}
		}

	}

	@Test
	public void testMessageReceiver() throws Exception {
		messageReceiver.receive(JmsConfig.DEFAULT_DESTINATION_NAME);

		messageSender.send(JmsConfig.DEFAULT_DESTINATION_NAME, "hellow activemq!");

	}

	//	@Test
	//	public void testMessageSender() throws Exception {
	//		messageSender.send(JmsConfig.DEFAULT_DESTINATION_NAME, "hellow activemq!");
	//	}
}
